package ch11;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

class _23_PropertiesEx2 {
	public static void main(String[] args) {
		Properties prop = new Properties();
		String dir = _23_PropertiesEx2.class.getResource(".").getPath();
		String inputFile = "_23_input.properties";

		try {
			prop.load(new FileInputStream(dir+inputFile));
		} catch (IOException e) {
			System.out.println(e);
			System.exit(0);
		}

		String name = prop.getProperty("name");
		String[] data = prop.getProperty("data").split(",");
		int max = 0;
		int min = 0;
		int sum = 0;

		for (int i = 0; i < data.length; i++) {
			int intValue = Integer.parseInt(data[i]);
			if (i == 0)	max = min = intValue;

			if (max < intValue) max = intValue;
			else if (min > intValue) min = intValue;
			sum += intValue;
		}

		System.out.println("name: " + name); // name: jerry
		System.out.println("max: " + max); // max: 35
		System.out.println("min: " + min); // min: 1
		System.out.println("sum: " + sum); // sum: 111
		System.out.println("average: " + (sum/data.length)); // average: 11
	}
}